//
//  BanBenInfoViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/11/9.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "BanBenInfoViewController.h"
#import "JTCSM.h"
#import "MyDoubleLabelView.h"
#import "MyInfoView.h"
#import "GetInfoClass.h"
#import <PgyUpdate/PgyUpdateManager.h>

static CGFloat myinfoHeight = 40;
@interface BanBenInfoViewController ()
{
    MyDoubleLabelView *titleView;
    UIScrollView *backScrollV;
}
@end

@implementation BanBenInfoViewController
- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.hidden = NO;
    [df isRemoveTarbar:YES];
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
       // Do any additional setup after loading the view.
    [self layoutView];
    [[GetInfoClass shareSingle] getBanbeninfo];
    
    [GetInfoClass shareSingle].myblock = ^(UserInfoModel *Model) {
        MyInfoView *view1 = [backScrollV viewWithTag:107];
        MyInfoView *view2 = [backScrollV viewWithTag:108];
        MyInfoView *view3 = [backScrollV viewWithTag:109];
        view1.footerLabel.text = Model.wechat;
        view2.footerLabel.text = Model.website;
        view3.footerLabel.text = Model.weibo;
    };
}

- (void)layoutView{
    
    backScrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, KCONTROLLERHeight-30)];
    backScrollV.backgroundColor = [UIColor whiteColor];
    backScrollV.userInteractionEnabled = YES;
    backScrollV.bounces = NO;
    backScrollV.showsVerticalScrollIndicator = NO;
    [self.view addSubview:backScrollV];
    
    NSArray *array2 = @[@"官方微信",@"官方网站",@"官方微博",@"检查更新"];

    CGFloat headerImageVHeight = KCONTROLLERWith*0.3133;
    UIImageView *headerImageV  = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,KCONTROLLERWith,headerImageVHeight)];
    headerImageV.image = [UIImage imageNamed:@"bg_banner6@2x.png"];
    [backScrollV addSubview:headerImageV];

    
    CGFloat imageSize = 100;
    CGFloat ImageTop = KVIEW_Y(headerImageV)-headerImageVHeight/2;
    UIImageView *logoImageV  = [[UIImageView alloc]initWithFrame:CGRectMake((KCONTROLLERWith-imageSize)/2, ImageTop, imageSize, imageSize)];
    logoImageV.image = [UIImage imageNamed:@"logoImageView.png"];
    [backScrollV addSubview:logoImageV];
    
    titleView = [[MyDoubleLabelView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(logoImageV)+10, KCONTROLLERWith, 0) titleFontsize:20 titlecolor:RGBACOLOR(89, 89, 89, 1) contentFontsize:18 contentcolor:RGBACOLOR(100, 100, 100, 1)];
    [titleView setvalueWithModel:@{KDoubleLabelTitle:@"王者管家",KDoubleLabelContent:KBanBenInfo}];
    [backScrollV addSubview:titleView];
    for (int i = 0; i < array2.count; i++) {
        MyInfoView *view3 = [[MyInfoView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(titleView)+10+myinfoHeight*i, KCONTROLLERWith, myinfoHeight) imagename:nil title:array2[i] placeholder:nil isShowLabel:(i == array2.count-1)?ImageViewType:labelType radioBtnIndex:0 GroupId:@"banbeninfo"];
        view3.tag = 107+i;
        view3.userInteractionEnabled = YES;
        if(array2.count==4){
            [df addTapGestureRecognizerWithTarget:self action:@selector(gotoVC:) andaddView:view3];
        }        [backScrollV addSubview:view3];
        [backScrollV setContentSize:CGSizeMake(KCONTROLLERWith, KVIEW_Y(view3)+20)];

    }

}
- (void)gotoVC:(UITapGestureRecognizer *)tap{
    
    [[PgyUpdateManager sharedPgyManager] checkUpdateWithDelegete:self selector:@selector(updateMethod:)];
//    [[PgyUpdateManager sharedPgyManager] checkUpdate];
}
- (void)updateMethod:(id)response{
    if (response != nil) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:response[@"downloadURL"]]];
        [[PgyUpdateManager sharedPgyManager] updateLocalBuildNumber];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
